package com.gta.edu.sdk.base.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gta.edu.sdk.base.dao.IBaseDao;
import com.gta.edu.sdk.base.service.IBaseService;
import com.gta.edu.sdk.common.dto.Page;
import com.gta.edu.sdk.common.dto.Sort;
import com.gta.edu.sdk.mybatis.common.Entity;

/**
 * @description 通用业务实现
 * @author fengya
 * @2017年5月18日
 */
@Service("baseService")
public class BaseServiceImpl<T> implements IBaseService<T> {
	@Autowired
	private IBaseDao<T> baseDao;

	@Override
	public void save(Entity entity) {
		this.baseDao.save(entity);
	}

	@Override
	public void update(Entity entity) {
		this.baseDao.update(entity);
	}

	@Override
	public void saveOrUpdate(Entity entity) {
		this.baseDao.saveOrUpdate(entity);
	}

	@Override
	public void delete(Class<? extends Entity> cls, String id) {
		this.baseDao.delete(cls, id);
	}
	
	@Override
	public void delete(Class<? extends Entity> cls, String[] ids) {
		for (String id : ids) {
			this.baseDao.delete(cls, id.trim());
		}
	}

	@Override
	public <E> E get(Class<E> cls, String id) {
		return this.baseDao.get(cls, id);
	}

	@Override
	public List<T> findAll(Class<T> cls, boolean isDefaultSort, Sort sort, boolean isDefaultDel) {
		return this.baseDao.findAll(cls, isDefaultSort, sort, isDefaultDel);
	}

	@Override
	public <E> List<E> findAllBySQL(Class<E> cls, String sqlContext, Sort sort, boolean isDefaultSort, Object... parameters) {
		return this.baseDao.findAllBySQL(cls, sqlContext, sort, isDefaultSort, parameters);
	}

	@Override
	public <E> void findPageBySql(Class<E> clazz, String sqlContext, Page<E> page, Object... parameters) {
		this.baseDao.findPageBySql(clazz, sqlContext, page, parameters);
	}

//	@Override
//	public void findAsPage(Page<T> page, Sort sort, T t, boolean isDefaultSort) {
//		this.baseDao.findAsPage(page, sort, t, isDefaultSort);
//	}

}
